package carmensd.vista

//import org.uqbar.arena.windows.SimpleWindow
import applicationModel.ViajarAppModel
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.tables.Table
import modelo.Pais
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.windows.SimpleWindow

//la pongo como MainWindow para probarla aislada pero es Simple window
class ViajarWindow extends SimpleWindow<ViajarAppModel> {

	new(WindowOwner parent, ViajarAppModel model) {
		super(parent, model)
	}

	//	new(WindowOwner parent, ViajarAppModel model) {
	//		super(parent, model)
	//	}
	//	
	override protected createFormPanel(Panel mainPanel) {
		this.title = "Viajar"
		mainPanel.setLayout(new VerticalLayout())

//		new Label(mainPanel).setText("Estas en: " + this.modelObject.recorridoPaises.lastElement)

		this.colocarTabla(mainPanel, "paisEnQueEstoy.paisesConConexionAerea", "paisSeleccionado")

		this.colocarBotones(mainPanel)

	}

	def colocarBotones(Panel panel) {
		var Panel panelChico = new Panel(panel)
		panelChico.setLayout(new HorizontalLayout())

		new Button(panelChico) => [
			caption = "Volver al país anterior"
			onClick = [|this.modelObject.volver()]
		]

		new Button(panelChico) => [
			caption = "Viajar"
			onClick = [|this.modelObject.viajar()]
		]

	}

	def colocarTabla(Panel panel, String items, String seleccionado) {
		var table = new Table<Pais>(panel, typeof(Pais))
		table.height = 90
		table.width = 120
		table.bindItemsToProperty(items)
		table.bindValueToProperty(seleccionado)
		this.describeResultsGrid(table)
	}

	def describeResultsGrid(Table<Pais> table) {
		new Column<Pais>(table).setTitle("Pais").bindContentsToProperty("nombre");
	}

	override protected addActions(Panel actionsPanel) {
	}
}
